package ltd.dujiabao.capability.domain.capmng.sync.feature;

import java.util.Optional;

import org.springframework.stereotype.Component;

import ltd.dujiabao.capability.common.dto.ErrorCodes;
import ltd.dujiabao.capability.common.exception.BusinessException;
import ltd.dujiabao.capability.domain.capmng.sync.Puller;
import ltd.dujiabao.capability.domain.capmng.sync.SyncCapabilityContext;

/**
 * @author : DuJiabao
 * @Project : ddd-capability
 * @Time : 2024/4/8 21:57
 * @Desc :
 */
@Component
public class FeaturePuller implements Puller {
    @Override
    public Object pullCapability(SyncCapabilityContext context) {
        return Optional.ofNullable(context.getAttribute("features"))
                .map(String::valueOf)
                .map(Long::valueOf)
                .orElseThrow(() -> new BusinessException(ErrorCodes.FEATURES_NOT_FOUND));
    }
}
